<?php echo $header; ?>

<?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
  
<?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
<?php } ?>

<div class="box">
  <div class="left"></div>
  <div class="right"></div>
  <div class="heading">
	<h1><img src="view/image/payment.png" alt="" /> <?php echo $heading_title; ?></h1>
	<div class="buttons"><a onclick="location = '<?php echo $insert; ?>'" class="button"><span><?php echo $button_insert; ?></span></a><a onclick="document.getElementById('form').submit();" class="button"><span><?php echo $button_delete; ?></span></a></div>
  </div>
  <div class="content">
	<form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
	  <table class="list">
		<thead>
		  <tr>
			<td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
			<td class="left"><?php if ($sort == 'v.order_id') { ?>
				<a href="<?php echo $sort_order_id; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_order_id; ?></a>
				<?php } else { ?>
				<a href="<?php echo $sort_order_id; ?>"><?php echo $column_order_id; ?></a>
				<?php } ?></td>
			<td class="left"><?php if ($sort == 'v.code') { ?>
			  <a href="<?php echo $sort_code; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_code; ?></a>
			  <?php } else { ?>
			  <a href="<?php echo $sort_code; ?>"><?php echo $column_code; ?></a>
			  <?php } ?></td>
			<td class="left"><?php if ($sort == 'v.from_name') { ?>
			  <a href="<?php echo $sort_from; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_from; ?></a>
			  <?php } else { ?>
			  <a href="<?php echo $sort_from; ?>"><?php echo $column_from; ?></a>
			  <?php } ?></td>
			<td class="left"><?php if ($sort == 'v.to_name') { ?>
			  <a href="<?php echo $sort_to; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_to; ?></a>
			  <?php } else { ?>
			  <a href="<?php echo $sort_to; ?>"><?php echo $column_to; ?></a>
			  <?php } ?></td>
			<td class="right"><?php if ($sort == 'v.amount') { ?>
			  <a href="<?php echo $sort_amount; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_amount; ?></a>
			  <?php } else { ?>
			  <a href="<?php echo $sort_amount; ?>"><?php echo $column_amount; ?></a>
			  <?php } ?></td>
			
			<?php if (1==0) {?>
			  <td class="left"><?php if ($sort == 'theme') { ?>
				<a href="<?php echo $sort_theme; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_theme; ?></a>
				<?php } else { ?>
				<a href="<?php echo $sort_theme; ?>"><?php echo $column_theme; ?></a>
				<?php } ?></td>
			<?php } ?>
			
			<td class="left"><?php if ($sort == 'v.status') { ?>
			  <a href="<?php echo $sort_status; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_status; ?></a>
			  <?php } else { ?>
			  <a href="<?php echo $sort_status; ?>"><?php echo $column_status; ?></a>
			  <?php } ?></td>
			<td class="left"><?php if ($sort == 'v.date_added') { ?>
			  <a href="<?php echo $sort_date_added; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_date_added; ?></a>
			  <?php } else { ?>
			  <a href="<?php echo $sort_date_added; ?>"><?php echo $column_date_added; ?></a>
			  <?php } ?></td>
			<td class="right"><?php echo $column_action; ?></td>
		  </tr>
		</thead>
		<tbody>
		  <?php if ($giftcards) { ?>
			<?php foreach ($giftcards as $giftcard) { ?>
			  <tr>
				<td style="text-align: center;">
				  <?php if ($giftcard['selected']) { ?>
					<input type="checkbox" name="selected[]" value="<?php echo $giftcard['giftcard_id']; ?>" checked="checked" />
				  <?php } else { ?>
					<input type="checkbox" name="selected[]" value="<?php echo $giftcard['giftcard_id']; ?>" />
				  <?php } ?>
				</td>
				<td class="left"><?php echo $giftcard['order_id']; ?></td>
				<td class="left"><?php echo $giftcard['code']; ?></td>
				<td class="left"><?php echo $giftcard['from']; ?></td>
				<td class="left"><?php echo $giftcard['to']; ?></td>
				<td class="right"><?php echo $giftcard['amount']; ?></td>
				
				<?php if(1==0){ ?>
				  <td class="left"><?php echo $giftcard['theme']; ?></td>
				<?php } ?>
				
				<td class="left"><?php echo $giftcard['status']; ?></td>
				<td class="left"><?php echo $giftcard['date_added']; ?></td>
				<td class="right">
				  <?php if(1==0){ ?>  
					[ <a onclick="sendGiftcard('<?php echo $giftcard['giftcard_id']; ?>');"><?php echo $text_send; ?></a> ]
				  <?php } ?>
				  
				  <?php foreach ($giftcard['action'] as $action) { ?>
					[ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
				  <?php } ?>
				</td>
			  </tr>
			<?php } ?>
		  <?php } else { ?>
			<tr>
			  <td class="center" colspan="9"><?php echo $text_no_results; ?></td>
			</tr>
		  <?php } ?>
		</tbody>
	  </table>
	</form>
	<div class="pagination"><?php echo $pagination; ?></div>
  </div>
</div>

<script type="text/javascript"><!--
function sendGiftcard(giftcard_id) {
	$.ajax({
		type: 'POST',
		url: 'index.php?route=sale/giftcard/send&token=<?php echo $token; ?>&giftcard_id=' + giftcard_id,
		dataType: 'json',
		beforeSend: function() {
			$('.success, .warning').remove();
			$('.box').before('<div class="attention"><img src="view/image/loading.gif" alt="" /> <?php echo $text_wait; ?></div>');
		},
		complete: function() {
			$('.attention').remove();
		},
		success: function(json) {
			if (json['error']) {
				$('.box').before('<div class="warning">' + json['error'] + '</div>');
			}
			
			if (json['success']) {
				$('.box').before('<div class="success">' + json['success'] + '</div>');
			}		
		}
	});
}
//--></script> 
<?php echo $footer; ?>